package com.atguigu.servicecms.controller;

import com.atguigu.commonutils.R;
import com.atguigu.servicecms.entity.CrmBanner;
import com.atguigu.servicecms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JY
 * @create 2021-01-27 20:21
 */
@RestController
@RequestMapping("/servicecms/bannerFront")
//@CrossOrigin
public class CrmBannerFrontController {
    @Autowired
    private CrmBannerService bannerService;

    //获取最新两个首页
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @GetMapping("getFrontBanner")
    public R getFrontBanner(){
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");
        wrapper.last("limit 2");
        List<CrmBanner> list = bannerService.list(wrapper);
        return R.ok().data("bannerList",list);
    }
}
